package com.hdaccp.foodsales.controller;

import com.hdaccp.foodsales.dao.GonghuoDao;
import com.hdaccp.foodsales.dao.jinhuolsDao;
import com.hdaccp.foodsales.entity.Gonghuo;
import com.hdaccp.foodsales.entity.Jinhuols;
import com.hdaccp.foodsales.entity.Shangpin;
import com.hdaccp.foodsales.service.jinhuolsService;
import com.hdaccp.foodsales.service.shangpinService;
import com.hdaccp.foodsales.service.xiaoshoulsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/jinhuols")
@Scope("prototype")
public class jinhuolsController {
    @Autowired
    private jinhuolsService jinhuolsService;
    @Autowired
    private jinhuolsDao jinhuolsDao;


    @RequestMapping("/delet")
    @ResponseBody
    public int delet(int id){
        System.out.println(id+"---");
        return jinhuolsDao.del(id);
    }


    @RequestMapping("/addls")
    @ResponseBody
    public int addls(Jinhuols jinhuols){
        return jinhuolsService.addls(jinhuols);
    }

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> querySearch(String huoname,int offset, int limit){
        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",jinhuolsService.findAll(huoname,offset,limit)) ;
        map.put("total",jinhuolsService.findTotalCount(huoname)) ;
        return  map ;
    }

    @RequestMapping("/all")
    @ResponseBody
    public boolean all(String huoname, int offset, int limit){
        boolean isok = false;
        if (jinhuolsService.findAll(huoname,offset,limit).size() == 0){
            isok = true;
        }

        return  isok ;
    }

    @RequestMapping("/query1")
    @ResponseBody
    public List<Gonghuo> query1(){
        List<Gonghuo> list=jinhuolsService.query1();
        for (Gonghuo r:list){
            r.getGhuo();
        }
     return list;
    }

}
